//////////////////////////////////////////////////////////////////////////
// PeekPocket - the hassle-free WiFi scanner for Windows Mobile
// coded by dzolee
// http://dzolee.blogspot.com
//
// Log - simple logger routines
//////////////////////////////////////////////////////////////////////////

#include "log.h"
#include <stdio.h>
#include <tchar.h>

HANDLE g_hlogfile;
TCHAR g_szFile[MAX_PATH]={_T("pplog.txt")};

//////////////////////////////////////////////////////////////////////////
void loginit()
{
#ifdef _DEBUG
	g_hlogfile=CreateFile(g_szFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
#endif
}

//////////////////////////////////////////////////////////////////////////
void loguninit()
{
#ifdef _DEBUG
	FlushFileBuffers(g_hlogfile);
	CloseHandle(g_hlogfile);
#endif
}

//////////////////////////////////////////////////////////////////////////
void logmsg(const char *formatstring, ...)
{
#ifdef _DEBUG
char temp[4096];
DWORD written;

	if(g_hlogfile != INVALID_HANDLE_VALUE)
	{
		va_list args;
		va_start(args, formatstring);
		_vsnprintf(temp, sizeof(temp), formatstring, args);
		strcat(temp, "\n");
		WriteFile(g_hlogfile, temp, strlen(temp), &written, 0);
		va_end(args);
	}

#endif
}